package com.liujun.microserver.auth2.password.server.api;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {
	
	@RequestMapping("/api/userinfo")
	public ResponseEntity<UserInfo> getUserinfo() {
		User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

		UserInfo users = new UserInfo();

		users.setEmail(user.getUsername() + "@spring2go.com");
		users.setUserName(user.getUsername());

		return ResponseEntity.ok(users);
	}

}
